import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:kxy_flutter_app/model/exam_question.dart';
import 'package:kxy_flutter_app/view/examination/question/question_widget.dart';

class QuestionSwiperWidget extends StatelessWidget {
  final SwiperController swiperCtrl;
  final List<Question> questionList;
  final Function(int) onChangeIndex;
  final Function(String) setAnswer;
  final bool canScroll;
  final bool withResult;

  const QuestionSwiperWidget({
    Key key,
    @required this.swiperCtrl,
    @required this.questionList,
    @required this.onChangeIndex,
    @required this.setAnswer,
    this.canScroll = true,
    this.withResult = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Swiper.children(
      loop: false,
      duration: 300,
      controller: swiperCtrl,
      physics: canScroll ? ClampingScrollPhysics() : NeverScrollableScrollPhysics(),
      onIndexChanged: (index) {
        onChangeIndex(index);
      },
      children: quesWidgetList(),
    );
  }

  List<Widget> quesWidgetList() {
    return questionList.map((ques) {
      return QuestionWidget(
        question: ques,
        withResult: withResult,
        checkCallback: (answer) {
          setAnswer(answer);
        },
      );
    }).toList();
  }
}
